package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class DtsBrandServiceImpl implements DtsBrandService {

    @Autowired
    DtsBrandMapper brandMapper;

    @Override
    public List<Integer> queryByAdminId(Integer adminId) {

        LambdaQueryWrapper<DtsBrand> qw = new LambdaQueryWrapper<>();
        qw.eq(DtsBrand::getAdminId, adminId);
        qw.select(DtsBrand::getId);
        List<DtsBrand> brandList = brandMapper.selectList(qw);

        List<Integer> ids = brandList.stream().map(dtsBrand -> {
            return dtsBrand.getId();
        }).collect(Collectors.toList());

        return ids;
    }

    @Override
    public List<Map<String, Object>> findBrand() {
        LambdaQueryWrapper<DtsBrand> qw = new LambdaQueryWrapper<>();
        qw.eq(DtsBrand::getDeleted, false);
        List<DtsBrand> brands = brandMapper.selectList(qw);

        List<Map<String, Object>> list = brands.stream().map(brand -> {
            Map<String, Object> map = new HashMap<>();
            map.put("value", brand.getId());
            map.put("label", brand.getName());
            return map;
        }).collect(Collectors.toList());

        return list;
    }
}
